/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.jini; import java.beans.*; import java.util.*; import javax.swing.*; import net.jini.discovery.*; /** * A dialog for creating new multicast discovery. * * @author Petr Kuzel * @version */ public class SelectGroups extends javax.swing.JPanel implements PropertyChangeListener { DefaultComboBoxModel cbmodel; /** Creates new form SelectGroups */ public SelectGroups() { initComponents (); group = new javax.swing.ButtonGroup(); group.add(allGroups); group.add(custom); allGroups.setSelected(true); BrowserModel browser = BrowserModel.getDefault(); browser.addPropertyChangeListener(this); String[] items = browser.getDiscoveredGroups(); cbmodel = new DefaultComboBoxModel(items); groupComboBox.setModel(cbmodel); setPreferredSize (new java.awt.Dimension(250, 300)); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents allGroups = new javax.swing.JRadioButton (); custom = new javax.swing.JRadioButton (); groupComboBox = new javax.swing.JComboBox (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; setPreferredSize (new java.awt.Dimension(160, 200)); setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(4, 4, 4, 4))); allGroups.setText ("All groups"); allGroups.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { allGroupsActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints1.weightx = 1.0; add (allGroups, gridBagConstraints1); custom.setText ("Custom"); custom.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { customActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; add (custom, gridBagConstraints1); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 24, 4, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add (groupComboBox, gridBagConstraints1); }//GEN-END:initComponents private void customActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customActionPerformed // Add your handling code here: groupComboBox.setEnabled(true); }//GEN-LAST:event_customActionPerformed private void allGroupsActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allGroupsActionPerformed // Add your handling code here: groupComboBox.setEnabled(false); }//GEN-LAST:event_allGroupsActionPerformed /** @return user selection. */ public String[] getGroups() { if (allGroups.isSelected()) return LookupDiscovery.ALL_GROUPS; else try { return new String[] { groupComboBox.getSelectedItem().toString() }; } catch (NullPointerException ex) { // not item selected return no groups #5875 return LookupDiscovery.NO_GROUPS; } } /** Notify that the source brovser has changed state. */ public void propertyChange(final PropertyChangeEvent e) { if ("services".equals(e.getPropertyName()) ) { String[] grps = ((BrowserModel)e.getSource()).getDiscoveredGroups(); for (int i = 0; i<grps.length; i++) { if (0 > cbmodel.getIndexOf(grps[i])) cbmodel.addElement(grps[i]); } } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton allGroups; private javax.swing.JRadioButton custom; private javax.swing.JComboBox groupComboBox; // End of variables declaration//GEN-END:variables private javax.swing.ButtonGroup group; } /* * <<Log>> * 5 Gandalf-post-FCS1.3.1.0 3/1/00 Petr Kuzel bug fix * 4 Gandalf 1.3 2/3/00 Petr Kuzel Be smart and documented * 3 Gandalf 1.2 2/2/00 Petr Kuzel Jini module upon 1.1alpha * 2 Gandalf 1.1 10/23/99 Ian Formanek NO SEMANTIC CHANGE - Sun * Microsystems Copyright in File Comment * 1 Gandalf 1.0 7/30/99 Martin Ryzl * $ */